
import {KEY} from '../../secretKey.js';
const API_KEY = KEY; // 替换为你的 DeepSeek API 密钥
const API_URL = import.meta.env.VITE_APP_BASE_API; // 替换为 DeepSeek API 的 URL

export const sendMessage = async (messages) => {
  try {
    const response = await fetch(API_URL, {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${API_KEY}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        messages: messages,
        model: "deepseek-chat",
        stream: true,
      }),
    });

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    return response.body; // 返回可读流
  } catch (error) {
    console.error('Error sending message:', error);
    throw error;
  }
};